package com.yang.frost.blueberry.weixin.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.yang.frost.blueberry.util.HttpRequestUtil;
import com.yang.frost.blueberry.weixin.config.WxConfig;
import com.yang.frost.blueberry.weixin.params.WxBaseParam;
import com.yang.frost.blueberry.weixin.service.WxMenuService;
import com.yang.frost.blueberry.weixin.service.WxService;
import com.yang.frost.blueberry.weixin.service.WxUmsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author 10296
 * @date 2021/4/14
 * @Description:
 */
@Service
public class WxMenuServiceImpl implements WxMenuService {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private WxService wxService;
    @Autowired
    private HttpRequestUtil requestUtil;

    @Override
    public Map<String, Object> createMenu(WxBaseParam param) throws Exception {
        String accessToken = wxService.getAccessToken();
        String url = String.format(WxConfig.CREATE_MENU, accessToken);
        JSONObject result = requestUtil.httpsRequest(url, "POST", param.getContent());
        logger.info(result + "");
        return result;
    }

    @Override
    public Map<String, Object> getCurrentSelfMenuInfo(WxBaseParam param) throws Exception {
        String accessToken = wxService.getAccessToken();
        String url = String.format(WxConfig.GET_CURRENT_SELFMENU_INFO, accessToken);
        JSONObject result = requestUtil.httpsRequest(url, "GET", param.getContent());
        logger.info(result + "");
        //解析


        return result;
    }

    @Override
    public Map<String, Object> deleteMenu(WxBaseParam param) throws Exception {
        String accessToken = wxService.getAccessToken();
        String url = String.format(WxConfig.DELETE_MENU, accessToken);
        JSONObject result = requestUtil.httpsRequest(url, "GET", param.getContent());
        logger.info(result + "");
        return result;
    }

    @Override
    public Map<String, Object> addConditionalMenu(WxBaseParam param) throws Exception {
        String accessToken = wxService.getAccessToken();
        String url = String.format(WxConfig.DELETE_MENU, accessToken);
        JSONObject result = requestUtil.httpsRequest(url, "POST", param.getContent());
        logger.info(result + "");
        return result;
    }

    @Override
    public Map<String, Object> delConditionalMenu(WxBaseParam param) throws Exception {
        return null;
    }

    @Override
    public Map<String, Object> tryMatchMenu(WxBaseParam param) throws Exception {
        return null;
    }
}
